<?php
/**
 * DMFramework
 * 
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @url http://dmframework.nl
 */

/**
 * @license Copyright 2012 Dillen Meijboom under the Apache license version 2.0 (http://apache.org/licenses/LICENSE-2.0)
 * @author Dillen Meijboom <info@dillenm.nl>
 * @package System.Library.Database.Adapter
 */
class Dmf_Database_Adapter_Abstract
{
    /**
     * Database settings
     * 
     * @var type 
     */
    protected $_settings;
    
    /**
     * Constructor
     * 
     * @param string settings
     * @throws Exception 
     */
    public function __construct( $settings )
    {
        if ( ! is_array( $settings ) )
        {
            $connections = Dmf_Application::getInstance()->getConfig()->asObject()->database->asArray();
            
            if ( ! isset( $connections[ $settings . '.engine'] ) )
            {
                throw new Exception( 'Connection name: "' . $settings . '" does not exist.' );
            }
            
            $this->_settings = array(
                'engine'    => $connections[ $settings . '.engine'],
                'username'  => $connections[ $settings . '.username'],
                'password'  => $connections[ $settings . '.password'],
                'server'    => $connections[ $settings . '.server'],
                'database'  => $connections[ $settings . '.database']
            );
        }
        else
        {
            $this->_settings = $settings;
        }
    }
}